﻿@ModelType PagedList.IPagedList(Of Product)

@Imports PagedList.Mvc
@Code
    ViewData("Title") = "Index"
End Code

@Scripts.Render("~/bundles/Product")
@Styles.Render("~/Content/Product_Update")

<div class="row">
    <div class="col-md-6">
        <div class="pagination-container">
            <ul class="pagination">
                <li>
                    @*@Html.ActionLink("Create New", "Create", nothing, New With {.class = "btn btn-primary btn-sm"})*@
                    <input type="submit" value="Create" class="btn btn-primary btn-sm btnCreate" />
                </li>
            </ul>
        </div>
    </div>

    <div class="col-md-6">
        @Html.PagedListPager(Model, Function(page) Url.Action("Index", New With { _
                                                                page, _
                                                                Key .sortOrder = ViewBag.CurrentSort, _
                                                                Key .currentFilter = ViewBag.CurrentFilter _
                                                            }))
    </div>
</div> 

<table class="table table-responsive">
    <tr class="success">
        <th>
            @Html.ActionLink(Html.DisplayNameFor(Function(model) model.FirstOrDefault.ProductName).ToHtmlString(), _
"Index", New With {Key .sortOrder = "productname_desc", .id = "lnkHeadProductName"})
            @*<a id="lnkHeadProductName">@Html.DisplayNameFor(Function(model) model.FirstOrDefault.ProductName)</a>*@
        </th>
        <th>
            @Html.DisplayNameFor(Function(model) model.FirstOrDefault.QuantityPerUnit)
        </th>
        <th>
            @Html.DisplayNameFor(Function(model) model.FirstOrDefault.UnitPrice)
        </th>
        <th>
            @Html.DisplayNameFor(Function(model) model.FirstOrDefault.UnitsInStock)
        </th>
        <th>
            @Html.DisplayNameFor(Function(model) model.FirstOrDefault.UnitsOnOrder)
        </th>
        <th>
            @Html.DisplayNameFor(Function(model) model.FirstOrDefault.ReorderLevel)
        </th>
        <th>
            @Html.DisplayNameFor(Function(model) model.FirstOrDefault.Discontinued)
        </th>
        <th>
            @Html.ActionLink(Html.DisplayNameFor(Function(model) model.FirstOrDefault.Category.CategoryName).ToHtmlString(), _
                "Index", New With {Key .sortOrder = "categoryname_desc"})
        </th>
        <th>
            @Html.ActionLink(Html.DisplayNameFor(Function(model) model.FirstOrDefault.Supplier.CompanyName).ToHtmlString(), _
                "Index", New With {Key .sortOrder = "companyname_desc"})
        </th>
        <th></th>
        <th></th>
    </tr>

    @For Each item In Model
        @<tr class="rowDetail">
            <td>
                @Html.DisplayFor(Function(modelItem) item.ProductName)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.QuantityPerUnit)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.UnitPrice)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.UnitsInStock)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.UnitsOnOrder)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.ReorderLevel)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.Discontinued)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.Category.CategoryName)
            </td>
            <td>
                @Html.DisplayFor(Function(modelItem) item.Supplier.CompanyName)
            </td>
            <td class="functionEdit">
                @*@Html.ActionLink("Edit", "Edit", New With {.id = item.ProductID}, New With {.class = "btnEdit"}) |
                    @Html.ActionLink("Details", "Details", New With {.id = item.ProductID}, New With {.class = "btnDetail"}) |
                    @Html.ActionLink("Delete", "Delete", New With {.id = item.ProductID}, New With {.class = "btnDelete"})*@

                @*<input type="submit" value="Edit" id="@(item.ProductID)" class="btn btn-sm btnEdit" onclick="location.href='@Url.Action("Edit", "Product"), new with {.id = item.ProductID}'" />*@
                @*<input type="submit" value="Edit" id="@(item.ProductID)" class="btn btn-sm btnEdit" />*@

                @*<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">*@

                @*<button class="btn btn-primary btn-sm ProductUpdate_btnEdit" data-id="@(item.ProductID)">
                            Edit
                    </button>*@
                <input type="button" value="Update" data-id="@(item.ProductID)" class="btn btn-primary btn-sm ProductUpdate_btnEdit" />
            </td>
            @*<td class="functionDetail">
                    <input type="submit" value="Details" class="btn btn-sm btnDetail" />
                </td>*@
            <td class="functionDelete">
                @Using (Html.BeginForm(Nothing, Nothing,FormMethod.Post, New With {.id="FunctionDeleteProduct"} ))
                    @Html.AntiForgeryToken()
                @<input type="submit" value="Delete" data-id="@(item.ProductID)" class="btn btn-primary btn-sm btnDelete" />
                End Using
            </td>
        </tr>
    Next
</table>

<div class="modal fade" id="edit-product" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" id="edit-product-container">
        </div>
    </div>
</div>

<div class="modal fade" id="progress-show" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" id="progress-show-container">
            @Html.Partial("~/Views/Shared/_ProgressShow.vbhtml")
        </div>
    </div>
</div>
